#include "engine.h"
#include <fstream>
#include <iostream>
#include <string>
#include <GL/glfw.h>

namespace HW
{
using namespace std;
ofstream* lLogFile;
int lLogMode = GL_TRUE;

void _i_InitLog ( const_str logFileName );
void _i_UnInitLog(void);

void AppLog(const_str text, int flags)
{
	if ( lLogMode == GL_FALSE )
		return;

	string lLogStr;
	if ( (flags&APPLOG_WARNING) != 0 )
		lLogStr.append ( "Error: " );
	lLogStr.append ( text );

	cout << lLogStr << endl;
	(*lLogFile) << lLogStr << endl;
	
	if ( (flags&APPLOG_ERROR) != 0 )
		MessageBoxA ( NULL , lLogStr.c_str() , "Error" , MB_OK|MB_ICONERROR|MB_TASKMODAL );
}

void AppLogMode(int mode)
{
	if ( mode == 1 )
		lLogMode = GL_TRUE;
	else
		lLogMode = GL_FALSE;
}

void _i_InitLog ( const_str logFileName )
{
	lLogFile = new ofstream ( logFileName );
}

void _i_UnInitLog(void)
{
	if ( lLogFile -> is_open ( ) )
		lLogFile -> close ( );
	delete lLogFile;
}

}